import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-05
 * Time: 13:08
 */
public class Test26 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int val) {
            this.val = val;
            next = null;
        }

    }

    public static ListNode detectCycle(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;

        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow) {
                break;
            }
        }
        // 特殊条件
        if(fast == null || fast.next == null) {
            return null;
        }

        fast = head;
        while(fast != slow) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ListNode head = null, tail = null;
        int n = sc.nextInt();
        for(int i = 0; i < n; i++) {
            int val = sc.nextInt();
            ListNode node = new ListNode(val);
            if(head == null) {
                head = node;
            } else {
                tail.next = node;
            }
            tail = node;
        }
        // 连接点
        int pos = sc.nextInt();
        ListNode node = head;
        for(int i = 0; i < pos; i++) {
            node = node.next;
        }
        tail.next = node;
        ListNode ret = detectCycle(head);
        System.out.println("该链表环形链表节点的值为："+ret.val);
        System.out.println("该链表环形链表节点索引："+pos);
    }
}


